import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/util/DateUtil.dart';

void main() {

  List<List<String>> monthGroup(List<String> days) {
    List<List<String>> result = [];
    String month = '';
    List<String> months = [];
    for (String day in days) {
      if (month == '') {
        month = day.substring(0, 7);
        months.add(day);
        if (months.length == 1) {
          result.add(months);
        }
      } else {
        if (day.startsWith(month)) {
          months.add(day);
          if (months.length == 1) {
            result.add(months);
          }
        } else {
          months = [];
          month = day.substring(0, 7);
          months.add(day);
          if (months.length == 1) {
            result.add(months);
          }
        }
      }
    }
    return result;
  }

  test("month group test", () async {
    var days = ['2024-08-21', '2024-08-20', '2024-08-11', '2024-08-02', '2024-08-01', '2024-07-01', '2024-06-01'];
    List<List<String>> months = monthGroup(days);
    for (var month in months) {
      var mstr = month.join(",");
      print("month: $mstr");
    }
  });

  test("dateTime parse", () async {
    var dayStr = '2024-08-21';
    var day = DateTime.parse(dayStr);
    print(DateUtil.formatDate(day));
  });

  test("dateTime sessionDay", () async {
    for (var i=20; i>0; i--) {
      var d = i < 10 ? "0${i}" : '$i';
      var dayStr = '2024-10-${d}';
      var day = DateTime.parse(dayStr);
      print(DateUtil.sessionShowTime(day));
    }

  });


}

